﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Player.MyAttribute;

namespace Player
{
    namespace DataTable
    {
        [View("Session")]
        public enum Session
        {
            [Column(SqlDbType.BigInt)]
            Id,
            [Column(SqlDbType.UniqueIdentifier)]
            Zone,
            [Column(SqlDbType.NVarChar, 255)]
            MachineName,
            [Column(SqlDbType.BigInt)]
            MachineAddress,
            [Column(SqlDbType.NVarChar, 255)]
            MachinePrincipal,
            [Column(SqlDbType.UniqueIdentifier)]
            SessionId,
            [Column(SqlDbType.Bit)]
            IsHeadRecord,
            [Column(SqlDbType.VarBinary, 85)]
            AgentSid,
            [Column(SqlDbType.NVarChar, 64, true)]
            TimeZone,
            [Column(SqlDbType.DateTime)]
            StartTime,
            [Column(SqlDbType.BigInt)]
            TimeStampOffset,
            [Column(SqlDbType.NVarChar, 511)]
            UserName,
            [Column(SqlDbType.NVarChar, 50)]
            UnixName,
            [Column(SqlDbType.NVarChar, 255)]
            DisplayName,
            [Column(SqlDbType.Bit)]
            IsAdUser,
            [Column(SqlDbType.VarBinary, 85)]
            AdUserSid,
            [Column(SqlDbType.NVarChar, 128)]
            Tty,
            [Column(SqlDbType.NVarChar, 255)]
            ClientName,
            [Column(SqlDbType.BigInt)]
            ClientAddress,
            [Column(SqlDbType.Int)]
            State,
            [Column(SqlDbType.DateTime, true)]
            EndTime,
            [Column(SqlDbType.Int)]
            AuditStoreId,
            [Column(SqlDbType.NVarChar, 64)]
            AuditStoreName,
            [Column(SqlDbType.Int)]
            AuditDatabaseId,
            [Column(SqlDbType.Bit)]
            AgentConnected,
            [Column(SqlDbType.TinyInt, false)]
            SessionType
        }

        [View("WashEvent")]
        public enum WashEvent
        {
            [Column(SqlDbType.BigInt)]
            Id,
            [Column(SqlDbType.UniqueIdentifier)]
            SessionId,
            [Column(SqlDbType.Int)]
            SequenceNumber,
            [Column(SqlDbType.BigInt)]
            SystemTime,
            [Column(SqlDbType.BigInt)]
            TimeStamp,
            [Column(SqlDbType.TinyInt)]
            Event,
            [Column(SqlDbType.Int)]
            Pid,
            [Column(SqlDbType.BigInt)]
            WindowId,
            [Column(SqlDbType.NVarChar, 512, true)]
            Module,
            [Column(SqlDbType.NVarChar, -1, true)] // nvarchar(max)
            Text,
            [Column(SqlDbType.Int)]
            X,
            [Column(SqlDbType.Int)]
            Y,
            [Column(SqlDbType.Int)]
            Width,
            [Column(SqlDbType.Int)]
            Height
        }

        [View("WashData")]
        public enum WashData
        {
            [Column(SqlDbType.BigInt)]
            Id,
            [Column(SqlDbType.UniqueIdentifier)]
            SessionId,
            [Column(SqlDbType.Int)]
            SequenceNumber,
            [Column(SqlDbType.BigInt)]
            SystemTime,
            [Column(SqlDbType.BigInt)]
            TimeStamp,
            [Column(SqlDbType.VarBinary, -1)]
            Data
        }

        [View("WashSession")]
        public enum WashSession
        {
            [Column(SqlDbType.BigInt)]
            Id,
            [Column(SqlDbType.UniqueIdentifier)]
            SessionId,
            [Column(SqlDbType.SmallInt)]
            PixelFormat,
            [Column(SqlDbType.VarBinary, 2048, true)]
            ColorMap
        }

        [View("Session")]
        public enum USession
        {
            [Column(SqlDbType.UniqueIdentifier)]
            Zone,
            [Column(SqlDbType.NVarChar, 255)]
            MachineName,
            [Column(SqlDbType.BigInt)]
            MachineAddress,
            [Column(SqlDbType.NVarChar, 255)]
            MachinePrincipal,
            [Column(SqlDbType.UniqueIdentifier)]
            Id,
            [Column(SqlDbType.Bit)]
            IsHeadRecord,
            [Column(SqlDbType.VarBinary, 85)]
            AgentSid,
            [Column(SqlDbType.DateTime)]
            StartTime,
            [Column(SqlDbType.NVarChar, 511)]
            UserName,
            [Column(SqlDbType.NVarChar, 50)]
            UnixName,
            [Column(SqlDbType.NVarChar, 255)]
            DisplayName,
            [Column(SqlDbType.Bit)]
            IsAdUser,
            [Column(SqlDbType.NVarChar, 255)]
            AdUserSid,
            [Column(SqlDbType.NVarChar, 128)]
            Tty,
            [Column(SqlDbType.NVarChar, 255)]
            ClientName,
            [Column(SqlDbType.BigInt)]
            ClientAddress,
            [Column(SqlDbType.Int)]
            State,
            [Column(SqlDbType.DateTime, true)]
            EndTime,
            [Column(SqlDbType.NVarChar, -1)]
            Comment,
            [Column(SqlDbType.Int)]
            AuditStoreId,
            [Column(SqlDbType.NVarChar, 64)]
            AuditStoreName,
            [Column(SqlDbType.Int)]
            AuditDatabaseId,
            [Column(SqlDbType.Bit)]
            AgentConnected,
            [Column(SqlDbType.TinyInt, false)]
            SessionType
        };

        [View("RawData")]
        public enum RawData
        {
            [Column(SqlDbType.BigInt)]
            Id,
            [Column(SqlDbType.UniqueIdentifier)]
            SessionId,
            [Column(SqlDbType.Int)]
            Sequence,
            [Column(SqlDbType.DateTime)]
            CapturedTime,
            [Column(SqlDbType.BigInt)]
            TimeStamp,
            [Column(SqlDbType.TinyInt)]
            Type,
            [Column(SqlDbType.Int, true)]
            ScreenWidth,
            [Column(SqlDbType.Int, true)]
            ScreenHeight,
            [Column(SqlDbType.Int, true)]
            PixelWidth,
            [Column(SqlDbType.Int, true)]
            PixelHeight,
            [Column(SqlDbType.VarBinary, -1, true)]
            TerminalData,
            [Column(SqlDbType.NVarChar, -1, true)]
            Tag,
            [Column(SqlDbType.Int, true)]
            LineNumber,
            [Column(SqlDbType.Bit)]
            IsEnterCommand
        };

        [View("Snapshot")]
        public enum Snapshot
        {
            [Column(SqlDbType.UniqueIdentifier)]
            SessionId,
            [Column(SqlDbType.Int)]
            Sequence,
            [Column(SqlDbType.DateTime)]
            CapturedTime,
            [Column(SqlDbType.BigInt)]
            TimeStamp,
            [Column(SqlDbType.VarBinary, -1, true)]
            TerminalData
        };

        [View("RawData")]
        public enum URawData
        {
            [Column(SqlDbType.UniqueIdentifier)]
            Session_Id,
            [Column(SqlDbType.Int)]
            Sequence,
            [Column(SqlDbType.DateTime)]
            CapturedTime,
            [Column(SqlDbType.Int)]
            Type,
            [Column(SqlDbType.Int, true)]
            ScreenWidth,
            [Column(SqlDbType.Int, true)]
            ScreenHeight,
            [Column(SqlDbType.Int, true)]
            PixelsWidth,
            [Column(SqlDbType.Int, true)]
            PixelsHeight,
            [Column(SqlDbType.VarBinary, -1, true)]
            TerminalData,
            [Column(SqlDbType.NVarChar, -1, true)]
            Tag,
            [Column(SqlDbType.Int, true)]
            CommandSequence,
            [Column(SqlDbType.Int)]
            Id
        };

        [Table("AuditStore")]
        [PrimaryConstraint(new int[] { (int)AuditStore.Id })]
        [UniqueConstraint(new int[] { (int)AuditStore.Name })]
        public enum AuditStore
        {
            [Column(SqlDbType.Int, false, true)]
            Id,
            [Column(SqlDbType.UniqueIdentifier)]
            Guid,
            [Column(SqlDbType.NVarChar, 64)]
            Name,
            [Column(SqlDbType.Bit)]
            TrustedAgentEnabled,
            [Column(SqlDbType.Bit)]
            TrustedCollectorEnabled,
            [Column(SqlDbType.Int)]
            ActiveDatabaseId
        }

        [Table("AuditStoreDatabase")]
        [PrimaryConstraint(new int[] { (int)AuditStoreDatabase.Id })]
        [UniqueConstraint(new int[] { (int)AuditStoreDatabase.Name })]
        public enum AuditStoreDatabase
        {
            [Column(SqlDbType.Int, false, true)]
            Id,
            [Column(SqlDbType.Int, false, false, typeof(AuditStore), (int)AuditStore.Id)]
            AuditStoreId,
            [Column(SqlDbType.UniqueIdentifier)]
            Guid,
            [Column(SqlDbType.NVarChar, 128)]
            Name,
            [Column(SqlDbType.NVarChar, 255)]
            Server,
            [Column(SqlDbType.NVarChar, 255)]
            Database,
            [Column(SqlDbType.Int)]
            Type                    // V1 database or V2 database
        }
        
        [View("Agent")]
        public enum Agent
        {
            [Column(SqlDbType.VarBinary, 85)]
            AgentSid,
            [Column(SqlDbType.VarBinary, 85)]
            CollectorSid,
            [Column(SqlDbType.NVarChar, 255)]
            AuditMachineName,
            [Column(SqlDbType.NVarChar, 30)]
            IPAddress,
            [Column(SqlDbType.Int)]
            UpdateInterval,   // the time interval (number of seconds) the agent will update its status
            [Column(SqlDbType.DateTime)]
            StartupTime,
            [Column(SqlDbType.DateTime)]
            LastUpdateTime
        }

        [Table("AuditStoreActiveDatabaseHistory")]
        [PrimaryConstraint(new int[] { (int)AuditStoreActiveDatabaseHistory.Id })]
        [UniqueConstraint(new int[] 
        { 
          (int)AuditStoreActiveDatabaseHistory.AuditStoreId, 
          (int)AuditStoreActiveDatabaseHistory.Guid 
        })]
        public enum AuditStoreActiveDatabaseHistory
        {
            [Column(SqlDbType.Int, false, true)]
            Id,
            [Column(SqlDbType.Int, false, false, typeof(AuditStore), (int)AuditStore.Id)]
            AuditStoreId,
            [Column(SqlDbType.UniqueIdentifier, false)]
            Guid,
            [Column(SqlDbType.DateTime, false)]
            ActiveTime
        }

        [Table("SystemProperty")]
        [PrimaryConstraint(new int[] { (int)SystemProperty.Name })]
        public enum SystemProperty
        {
            [Column(SqlDbType.NVarChar, 128)]
            Name,
            [Column(SqlDbType.Variant)]
            Value,
        }
        public enum SystemPropertyItem
        {
            [Property(SqlDbType.UniqueIdentifier)]
            SystemId,               // the id of the installation system

            [Property(SqlDbType.NVarChar, 64)]
            SystemName,             // the name of the installation system

            [Property(SqlDbType.NVarChar, 64)]
            SystemVersion,          // the version of the installation system

            [Property(SqlDbType.DateTime)]
            LastUpdateTime,         // last update time of installation name, Audit Server list.
            // Audit Store list, site list, scope list, license list

            [Property(SqlDbType.NVarChar, 128)]
            UserName,               // the username of the outgoing account of this Audit Server

            // TODO: we should encrypt the password, so the data type should be varbinary
            [Property(SqlDbType.NVarChar, 128)]
            Password,               // the password of the outgoing account of this Audit Server (if it is sql login)

            [Property(SqlDbType.Bit)]
            IsWindowsAuthentication,// the account type of the outgoing account of this Audit Server

            [Property(SqlDbType.NVarChar, 128)]
            DisplayName,            // the display name of this Audit Server

            [Property(SqlDbType.VarBinary, 85)]
            Administrator,          // the installation and Audit Server administrator
        }
    }
}